const regExp = {
    url: new RegExp('^((https|http|ftp|rtsp|mms)?://)' +
    '?(([0-9a-z_!~*\'().&=+$%-]+: )?[0-9a-z_!~*\'().&=+$%-]+@)?' + // ftp的user@
    '(([0-9]{1,3}.){3}[0-9]{1,3}' + // IP形式的URL- 199.194.52.184
    '|' + // 允许IP和DOMAIN（域名）
    '([0-9a-z_!~*\'()-]+.)*' + // 域名- www.
    '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' + // 二级域名
    '[a-z]{2,6})' + // first level domain- .com or .museum
    '(:[0-9]{1,4})?' + // 端口- :80
    '((/?)|' + // a slash isn't required if there is no file name
    '(/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+/?)$'),

    ipv4: /^((25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)\.){3}(25[0-5]|2[0-4]\d|1\d{2}|[1-9]?\d)$/g,
    // 内联IPV4、IPV6、IPV6缩写格式
    ipv6: /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/g,
    // 验证中文
    chinese: /^[\u4e00-\u9fa5]{0,}$/,
    // 数字
    number: /^[0-9]*$/,
    // 正整数
    justInt: /^\+?[1-9][0-9]*$/,
    // 手机
    mobile: /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/,
    // 固话
    fixPhone: /^((\d{3,4}-)|\d{3.4}-)?\d{7,8}$/,
    // 有两位小数的正实数
    numberDecimal_2: /^[0-9]+(\.[0-9]{1,2})?$/
}

export function validUrl(v) {
    return regExp.url.test(v)
}

/**
 * 验证中文
 * @param {*} v
 * @returns
 */
export function validChinese(v) {
    return regExp.chinese.test(v)
}

/**
 * 验证数字
 * @param {*} v
 * @returns
 */
export function validNumber(v) {
    return regExp.number.test(v)
}

/**
 * 验证正整数
 * @param {*} v
 * @returns
 */
export function validJustInt(v) {
    return regExp.justInt.test(v)
}

/**
 * 验证手机
 * @param {*} v
 * @returns
 */
export function validMobile(v) {
    return regExp.mobile.test(v)
}

/**
 * 验证固话
 * @param {*} v
 * @returns
 */
export function validFixPhone(v) {
    return regExp.fixPhone.test(v)
}

/**
 * 验证电话
 * @param {*} v
 * @returns
 */
export function validTelPhone(v) {
    return validMobile(v) || validFixPhone(v)
}

/**
 * 验证 有两位小数的正实数
 * @param {*} v
 * @returns
 */
export function validNumberDecimal_2(v) {
    return regExp.numberDecimal_2.test(v)
}
